<?php
/**************************************************************************************************
| Ionicware
| http://www.ionicware.com
| support@ionicware.com
|
|**************************************************************************************************
|
| Copyright (c) 2011 ionicware.com. All rights reserved.
|**************************************************************************************************/

include("include/config.php");
include("include/functions/import.php");
$pid = is_array($_REQUEST['id']) ? 0 : intval(strip_tags($_REQUEST['id'])); // ?x[]=: as on 7.4, not a TypeError (#1925)

if($pid > 0)
{
	/*
	 * User or staff is marking this
	 * answer as "is_answered"
	 * 12/12/2012
	 */
	 if (!empty($_REQUEST['is_answered']))
	 {
			/*
			 * Grab our answer ID
			 */
			$id = intval($_REQUEST['is_answered']);

			/*
			 * Make sure the user is the owner
			 */
			$sql 	 	   = "SELECT userid, total_answer FROM questions WHERE quesid={$id}";
			$executequery  = $conn->Execute($sql);
			$results 	   = $executequery->getrows();
			if ($results[0]['userid'] == $_SESSION['USERID'] || isStaff() || $_SESSION['USERGROUP'] == 'faqmod' || $_SESSION['USERGROUP'] == 'unpaidfaq') {
				/*
				 * It must have answers before it can be
				 * set to "is_answered"
				 */
				if ($results[0]['total_answer'] >= 1) {
					/*
					 * Update the time first
					 */
					$sql = "UPDATE questions SET is_answered=1 WHERE quesid={$id}";
					$conn->Execute($sql);
				}
			}
		}

		/*
		 * Staff is reopening a question
		 * 10/3/2013
		 */
		 if (!empty($_REQUEST['un_answered'])) {
		 	/*
			 * Grab our answer ID
			 */
			$id = intval($_REQUEST['un_answered']);

		 	if ((isStaff() || $_SESSION['USERGROUP'] == 'faqmod' || $_SESSION['USERGROUP'] == 'unpaidfaq') && $id > 0) {
				/*
				 * Update the time first
				 */
				$sql = "UPDATE questions SET is_answered=0 WHERE quesid={$id}";
				$conn->Execute($sql);
			}
		 }

		/*
		 * Staff is deleting
		 * 4/17/2012
		 */
		if (!empty($_REQUEST['deleteid']) && is_numeric($_REQUEST['deleteid']) && !empty($_REQUEST['deletetype'])
			&& (isStaff() || $_SESSION['USERGROUP'] == 'faqmod' || $_SESSION['USERGROUP'] == 'unpaidfaq')) {
			if (!empty($_REQUEST['reason']) && removeNonAlpha((is_array($_REQUEST['reason']) ? null : strtolower($_REQUEST['reason']))) != 'reason') { // ?x[]=: as on 7.4, not a TypeError (#1925)
				/*
				 * Clean data
				 */
				$id 	= escape($_REQUEST['deleteid']);
				$reason = escape($_REQUEST['reason']);

				/*
				 * Depending on type, there are different queries
				 */
				if ($_REQUEST['deletetype'] == 'answer') {
					$sql = "SELECT userid FROM answers WHERE ansid={$id}";
					$executequery  = $conn->Execute($sql);
					$results 	   = $executequery->getrows();
					$answerUserId  = $results[0]['userid'];

					/*
					 * descrease the users answer amount
					 */
					$sql = "UPDATE members SET total_answers=total_answers-1 WHERE USERID={$answerUserId}";
					$conn->Execute($sql);

					/*
					 * Delete the answer
					 */
					$sql = "UPDATE answers SET status=0 WHERE ansid={$id}";
					$conn->Execute($sql);

					/*
					 * Send a log!
					 */
					$actionText = "FAQ Delete Answer: {$id}";
					$reason     = $_REQUEST['reason'];

					/*
					 * Log all mod actions
					 */
					if (intval($_SESSION['ADMINID']) > 0)
					{
						InsertModeratorLog($actionText, $id, $_REQUEST['deletetype'], $reason);
					}
					InsertFaqModeratorLog($actionText, $id, $_REQUEST['deletetype'], $reason);

					$message = "Answer deleted";

				}
				else if ($_REQUEST['deletetype'] == 'question')
				{
					$sql = "SELECT userid FROM questions WHERE quesid={$id}";
					$executequery  = $conn->Execute($sql);
					$results 	   = $executequery->getrows();
					$quesUserId  = $results[0]['userid'];

					/*
					 * descrease the users answer amount
					 */
					$sql = "UPDATE members SET total_questions=total_questions-1 WHERE USERID={$quesUserId}";
					$conn->Execute($sql);

					/*
					 * Delete the answer
					 */
					$sql = "UPDATE questions SET status=0 WHERE quesid={$id}";
					$conn->Execute($sql);

					/*
					 * Send a log!
					 */
					$actionText = "FAQ Delete Question: {$id}";
					$reason     = $_REQUEST['reason'];

					/*
					 * Log all mod actions
					 */
					if (intval($_SESSION['ADMINID']) > 0)
					{
						InsertModeratorLog($actionText, $id, $_REQUEST['deletetype'], $reason);
					}
					InsertFaqModeratorLog($actionText, $id, $_REQUEST['deletetype'], $reason);

					$message = "Question deleted";
				}
			}
		}

		/*
		 * Staff has pressed the "Bad" button
		 * 10/3/2012
		 */
		if (!empty($_REQUEST['badid']) && is_numeric($_REQUEST['badid']) && !empty($_REQUEST['badtype']) && (isStaff() || $_SESSION['USERGROUP'] == 'faqmod' || $_SESSION['USERGROUP'] == 'unpaidfaq')) {
			/*
			 * Clean data
			 */
			$id 		   = escape($_REQUEST['badid']);
			$type   	   = escape($_REQUEST['badtype']);
			$warningreason = "Invalid FAQ content";
			$adminId	   = GetAdminIdFromUserId($_SESSION['USERID']);

			/*
			 * Depending on type, there are different queries
			 */
			if ($_REQUEST['badtype'] == 'answer') {
				$sql = "SELECT userid, answer FROM answers WHERE ansid={$id}";
				$executequery  = $conn->Execute($sql);
				$results 	   = $executequery->getrows();
				$answerUserId  = $results[0]['userid'];
				$badAnswer	   = $results[0]['answer'];

				/*
				 * Add some extra data to the warning
				 */
				$warningreason .= ": Answer - " . $badAnswer;

				/*
				 * Issue the warning
				 */
				GiveWarning($warningreason, $answerUserId, $_SESSION['USERID']);

				/*
				 * If more than 5 warnings, infract the user
				 */
				if (GetUserWarningCount($answerUserId) >= 5) {
					GiveInfraction($warningreason, $answerUserId, 15, $adminId);

					/*
					 * update the infracted
					 */
					$sql = "UPDATE members_warnings SET infracted=1 WHERE USERID={$answerUserId}";
					$conn->Execute($sql);
				}

				/*
				 * descrease the users answer amount
				 */
				$sql = "UPDATE members SET total_answers=total_answers-1 WHERE USERID={$answerUserId}";
				$conn->Execute($sql);

				/*
				 * Delete the answer
				 */
				$sql = "UPDATE answers SET status=0 WHERE ansid={$id}";
				$conn->Execute($sql);


			} else if ($_REQUEST['badtype'] == 'question') {
				$sql = "SELECT userid, question FROM questions WHERE quesid={$id}";
				$executequery  = $conn->Execute($sql);
				$results 	   = $executequery->getrows();
				$quesUserId    = $results[0]['userid'];
				$badQuestion   = $results[0]['question'];

				/*
				 * Add some extra data to the warning
				 */
				$warningreason .= ": Question - " . $badQuestion;

				/*
				 * Issue the warning
				 */
				GiveWarning($warningreason, $quesUserId, $_SESSION['USERID']);

				/*
				 * If more than 5 warnings, infract the user
				 */
				if (GetUserWarningCount($quesUserId) >= 5) {
					GiveInfraction($warningreason, $quesUserId, 15, $adminId);

					/*
					 * update the infracted
					 */
					$sql = "UPDATE members_warnings SET infracted=1 WHERE USERID={$quesUserId}";
					$conn->Execute($sql);
				}

				/*
				 * descrease the users answer amount
				 */
				$sql = "UPDATE members SET total_questions=total_questions-1 WHERE USERID={$quesUserId}";
				$conn->Execute($sql);

				/*
				 * Delete the answer
				 */
				$sql = "UPDATE questions SET status=0 WHERE quesid={$id}";
				$conn->Execute($sql);

				/*
				 * Forward back to FAQ
				 */
				header("Location: {$config['baseurl']}/faq");
				die();

			}


		}

		/*
		 * The user is editing their question
		 * 4/15/2012
		 */
		if (!empty($_REQUEST['editid']) && is_numeric($_REQUEST['editid']) && !empty($_REQUEST['edittype'])) {
			if (!empty($_REQUEST['edit_body'])) {
				if (((isStaff() || $_SESSION['USERGROUP'] == 'faqmod' || $_SESSION['USERGROUP'] == 'unpaidfaq')
						&& !empty($_REQUEST['reason']) && removeNonAlpha((is_array($_REQUEST['reason']) ? null : strtolower($_REQUEST['reason'])) /* ?x[]=: as on 7.4, not a TypeError (#1925) */) != 'reason')
							|| !isStaff()) {
					if (!DetectSpamLinkContent($_SESSION['USERID'], $_REQUEST['message_body'])) {	// !SearchForSpam($_REQUEST['edit_body']) &&
						/*
						 * Clean the tainted data
						 */
						$id   	= escape($_REQUEST['editid']);
						$text 	= escape(cleanit_keeptags($_REQUEST['edit_body']));
						$catId  = escape($_REQUEST['catId']);

						/*
						 * Depending on type, there are different queries
						 */
						if ($_REQUEST['edittype'] == 'answer') {
							/*
							 * Make sure the user is the owner
							 */
							$sql 	 	   = "SELECT userid FROM answers WHERE ansid={$id}";
							$executequery  = $conn->Execute($sql);
							$results 	   = $executequery->getrows();
							if ($results[0]['userid'] == $_SESSION['USERID'] || isStaff() || $_SESSION['USERGROUP'] == 'faqmod' || $_SESSION['USERGROUP'] == 'unpaidfaq') {

								if (!IsAnswerMadeAlready($_REQUEST['message_body']))
								{
									/*
									 * Update the time first
									 */
									$sql = "UPDATE answers SET updated=UNIX_TIMESTAMP(NOW()) WHERE ansid={$id}";
									$conn->Execute($sql);

									/*
									 * Copy a history
									 */
									$sql = "INSERT INTO answers_history (ansid, quesid, userid, parentid, answer, date_answered, status, ip_address, upvotes, downvotes, combined_votes, updated)
											SELECT ansid, quesid, userid, parentid, answer, date_answered, status, ip_address, upvotes, downvotes, combined_votes, updated
											FROM answers WHERE ansid={$id}";
									$conn->Execute($sql);

									/*
									 * Update the post
									 */
									$sql = "UPDATE answers SET answer='{$text}' WHERE ansid={$id}";
									$conn->Execute($sql);

									/*
									 * Blank out message
									 */
									$message = $lang['777'];
									$message_body = "";
									$_REQUEST['edit_body'] = "";

									/*
									 * Record Mod Activity
									 */
									if (isStaff() || $_SESSION['USERGROUP'] == 'faqmod' || $_SESSION['USERGROUP'] == 'unpaidfaq') {
										$actionText = "FAQ Answer Edit: {$id}";
										$reason     = $_REQUEST['reason'];

										/*
										 * Log all mod actions
										 */
										if (intval($_SESSION['ADMINID']) > 0)
										{
											InsertModeratorLog($actionText, $id, $_REQUEST['edittype'], $reason);
										}
										InsertFaqModeratorLog($actionText, $id, $_REQUEST['edittype'], $reason);
									}
								}
								else
								{
									/*
									 * Answer is already made
									 */
									$error = $lang['1527'];
								}
							}
						} else if ($_REQUEST['edittype'] == 'question') {
							if (!empty($_REQUEST['question']) && !empty($_REQUEST['tags'])) {
								if (1 == 1) { // !SearchForSpam($_REQUEST['question']) && !SearchForSpam($_REQUEST['tags'])


									/*
									 * Sanatize tainted data
									 */
									$question  = escape(cleanit_keeptags(ConditionTextBeforeSubmit($_REQUEST['question'])));
									$tags	   = escape(cleanit($_REQUEST['tags']));

									/*
									 * Create the SEO clean title
									 */
									$seoTitle = seo_clean_titles($question);

									/*
									 * Make sure the user is the owner
									 */
									$sql 	 	   = "SELECT userid FROM questions WHERE quesid={$id}";
									$executequery  = $conn->Execute($sql);
									$results 	   = $executequery->getrows();
									if ($results[0]['userid'] == $_SESSION['USERID'] || isStaff() || $_SESSION['USERGROUP'] == 'faqmod' || $_SESSION['USERGROUP'] == 'unpaidfaq') {

										if (1 == 1) // !IsQuestionAskedAlread($question)
										{
											/*
											 * Update the time
											 */
											$sql = "UPDATE questions SET updated=UNIX_TIMESTAMP(NOW()) WHERE quesid={$id}";
											$conn->Execute($sql);

											/*
											 * Copy history
											 */
											// $sql = "INSERT INTO questions_history (quesid, userid, username, metatitle, metakeywords, metadescription, question, seo, catid, description, tags, ip, total_answer, status, date_asked,date_answered, date_last_viewed, total_views, author_bookmarktip, api_bookmarked, upvotes, downvotes, combined_votes, updated)
											// 	SELECT quesid, userid, username, metatitle, metakeywords, metadescription, question, seo, catid, description, tags, ip, total_answer, status, date_asked,date_answered, date_last_viewed, total_views, author_bookmarktip, api_bookmarked, upvotes, downvotes, combined_votes, updated
											// 	FROM questions WHERE quesid={$id}";
											// $conn->Execute($sql);

											/*
											 * Update the question
											 */
											$sql = "UPDATE questions SET question='{$question}', seo='{$seoTitle}', description='{$text}', tags='{$tags}'";

											/*
											 * Only certain people can edit the
											 * category, not FAQ Mods
											 * 11/8/2016
											 */
											if (isStaff() && $catId > 0)
											{
												$sql .= ", catid='{$catId}'";
											}

											if (isStaff() || $_SESSION['USERGROUP'] == 'faqmod' || $_SESSION['USERGROUP'] == 'unpaidfaq')
											{
												$badges 			= escape(json_encode($_REQUEST['badges']));
												$sql				.= ", badges='{$badges}' ";
											}

											$sql .=	" WHERE quesid={$id}";
											$conn->Execute($sql);

											/*
											 * Blank out message
											 */
											$message = $lang['777'];
											$edit_body = "";
											$_REQUEST['edit_body'] = "";

											/*
											 * Record Mod Activity
											 */
											if (isStaff() || $_SESSION['USERGROUP'] == 'faqmod' || $_SESSION['USERGROUP'] == 'unpaidfaq') {
												$actionText = "FAQ Question Edit: {$id}";
												$reason     = $_REQUEST['reason'];

												/*
												 * Log all mod actions
												 */
												if (intval($_SESSION['ADMINID']) > 0)
												{
													InsertModeratorLog($actionText, $id, $_REQUEST['edittype'], $reason);
												}
												InsertFaqModeratorLog($actionText, $id, $_REQUEST['edittype'], $reason);
											}
										}
										else
										{
											// Question already asked
											$error .= $lang['592'];
										}
									}
								} else {
									/*
									 * Determine if the message is spam or not
									 */
									$error = $lang['748'];
								}
							} else {
								/*
								 * Title and tags cannot be empty
								 */
								$error = $lang['776'];
							}

						}
					} else {
						/*
						 * Determine if the message is spam or not
						 */
						$error = $lang['748'];
					}
				} else {
					/*
					 * No Reason code and is admin
					 */
					$error = $lang['779'];
				}
			} else {
				/*
				 * Blank Comment
				 */
				$error = $lang['605'];
			}
		}

	/*
	 * Article
	 */
	/*
	 * The header image is a LEFT JOIN on purpose: questions.image_id is 0
	 * for every discussion started before the field existed and for every
	 * one started without a picture since, and an attachment can be taken
	 * away underneath a discussion that does have one. An inner join would
	 * turn any of those into a 301 back to /faq.
	 *
	 * members_attachments is only ever the one in seoclerks, whichever
	 * site is serving the page - ProcessUploadedImage() writes there.
	 *
	 * 2026-09-20
	 */
	$query="SELECT q.*, c.seo as CatSEO, c.name as CatName, c.parentid,
					a.s as ImageShard, a.fname as ImageName
				FROM `questions` as q
				JOIN categories_faq as c ON q.catid=c.CATID
				LEFT JOIN seoclerks.members_attachments as a ON a.MAID=q.image_id
				WHERE (q.status=1 OR
						(q.status=2 AND q.userid='".escape($_SESSION['USERID'])."')
					  )
					AND q.quesid='".escape($pid)."'";

				// 				JOIN members as m ON q.userid=m.USERID,  m.USERID,
	$executequery 	= $conn->Execute($query);
	$p 				= $executequery->getrows();
	$fnd 			= count($p);

	/*
	 * Fetch the Title from the REQUEST
	 * 4/15/2012
	 */
	$title = $_REQUEST['title'];

	/*
	 * If the user is viewing the page
	 * from an ID only, lets move them
	 * to the SEO page.
	 * 11/26/2011
	 */
	if (empty($title) && stristr($_SERVER['REQUEST_URI'], '/viewfaq.php?id=') && $_REQUEST['ajax'] != 1) {
		$stitle = $p[0]['seo'];
		header("HTTP/1.1 301 Moved Permanently");
		header("location: $config[baseurl]/faq/{$pid}/{$stitle}");
	}

	/*
	 * Make sure the title is right
	 * and if not, move the User too
	 * 4/15/2012
	 */
	if ($title != $p[0]['seo'] && $_REQUEST['ajax'] != 1) {
		$stitle = $p[0]['seo'];
		header("HTTP/1.1 301 Moved Permanently");
		header("location: $config[baseurl]/faq/{$pid}/{$stitle}");
	}

	/*
	 * If the question is no longer there,
	 * forward the user back to the original
	 * FAQ section
	 * 8/2/2013
	 */
	if ($fnd <= 0)
	{
		header("HTTP/1.1 301 Moved Permanently");
		header("location: $config[baseurl]/faq");
	}

	$p[0]['orig'] 		 = ConditionOrig($p[0]['description']);
	$p[0]['image_url']	 = communityAttachmentUrl($p[0]['ImageShard'], $p[0]['ImageName']);

	/*
	 * Replace images here with a link to the actual
	 * image and then reduce the size here.
	 * 11/9/2012
	 */
	$images = getImagesFromContent($p[0]['description']);
	foreach ($images[0] as $key => $image) {
		//$p[0]['description'] = str_ireplace($image, '[url="' . $images[1][$key] . '"]' . $image . '[/url]', $p[0]['description']);
	}

	/*
	 * Added 10/8/2011 to this POS code
	 * to enable line breaks in text.
	 *
	 * Updated on 10/15/2011 for bbcode
	 */
	$userDetails	 	 = GetAllUserDetails($p[0]['userid']);
	$p[0]['username']	 = $userDetails['username'];
	$p[0]['userlevel']	 = $userDetails['userlevel'];
	// $p[0]['description'] = ReplaceAttachments($p[0]['quesid'], 'question', $p[0]['description']); // Function removed
	$p[0]['description'] = textConvertAffiliateSites($p[0]['description']);
	$p[0]['description'] = ConditionText($p[0]['description']);
	$p[0]['title'] 		 = strip_tags(replaceGig($p[0]['question']));
	$title 				 = cleanit($p[0]['question']);
	$p[0]['USERID'] 	 = $p[0]['userid'];
	$p[0]['PID'] 		 = $p[0]['quesid'];
	$p[0]['realurl'] 	 = "/faq/{$pid}/{$p[0]['seo']}";
	$p[0]['realurl'] 	 = base64_encode($p[0]['realurl']);
	$uname 				 = $p[0]['username'];
	$PD 				 = $p[0]['quesid'];
	$gtags 				 = FormatTags($p[0]['tags']);
	$p[0]['tags']		 = $gtags;
	$p[0]['display_date']= date("F j, Y, g:i a", $p[0]['date_asked']); //GetTimeAgo($p[0]['date_asked']); //date("F j, Y, g:i a", $p[0]['date_asked']); //GetDateBasedOnTimezone($p[0]['date_asked']);

	$uid 				 = $p[0]['userid'];

	$p[0]['poll_data'] = json_decode($p[0]['poll_data'], true);

	/**
	 * Grab poll data and calculate
	 * 2023-02-01 19:23:21 - SE
	 */
	foreach ($p[0]['poll_data'] as $key => &$value)
	{
		$value['percent'] = pollCalculation($pid, $key);
	}

	/*
	 * Set the updated date to the actual last update.
	 * 8/17/2018
	 */
	if ($p[0]['updated'] <= 0)
	{
		$p[0]['updated'] = $p[0]['date_asked'];
	}

	/*
	 * If the site is MBL, change all references of SC
	 * / Ionicware to MBL.
	 * 4/8/2014
	 */
	if ($config['baseurl'] == 'http://www.monsterbacklinks.com')
	{
		$p[0]['title']  = str_ireplace('SEOClerks.com', 'MonsterBacklinks.com', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('Seoclerks', 'Monster Backlinks', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('SEOClerk', 'Monster Backlinks', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('SEO Clerks', 'Monster Backlinks', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('SEO Clerk', 'Monster Backlinks', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('Ionicware', 'SeoMerTech', $p[0]['title'] );

		if ($p[0]['CatName'] == 'SEOClerks')
		{
			$p[0]['CatName'] = 'Monster Backlinks';
		}
	}
	else if ($config['baseurl'] == 'https://www.seocheckout.com')
	{
		$p[0]['title']  = str_ireplace('SEOClerks.com', 'Seocheckout.com', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('Seoclerks', 'Seocheckout', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('SEOClerk', 'Seocheckout', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('SEO Clerks', 'Seocheckout', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('SEO Clerk', 'Seocheckout', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('Ionicware', 'Seocheckout', $p[0]['title'] );

		if ($p[0]['CatName'] == 'SEOClerks')
		{
			$p[0]['CatName'] = 'Seocheckout';
		}
	}
	else if ($config['baseurl'] == 'https://www.seolads.com')
	{
		$p[0]['title']  = str_ireplace('SEOClerks.com', 'SEOLads.com', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('Seoclerks', 'SEOLads', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('SEOClerk', 'SEOLads', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('SEO Clerks', 'SEOLads', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('SEO Clerk', 'SEOLads', $p[0]['title'] );
		$p[0]['title']  = str_ireplace('Ionicware', 'SEOLads', $p[0]['title'] );

		if ($p[0]['CatName'] == 'SEOClerks')
		{
			$p[0]['CatName'] = 'SEOLads';
		}
	}

	/*
	 * Get all of the parents
	 * Category data for the nav
	 * 6/18/2016
	 */
	if ($p[0]['parentid'] > 0)
	{
		$parentCatDetails = GetCategorySeoFromType('faq', $p[0]['parentid']);

		if ($parentCatDetails['parentid'] > 0)
		{
			$pParentCatDetails 	= GetCategorySeoFromType('faq', $parentCatDetails['parentid']);

			if ($pParentCatDetails['parentid'] > 0)
			{
				$ppParentCatDetails 	= GetCategorySeoFromType('faq', $pParentCatDetails['parentid']);
				$preCategory[] 			= $ppParentCatDetails;
			}

			$preCategory[] 		= $pParentCatDetails;
		}

		$preCategory[] 		= $parentCatDetails;
	}


	/*
	 * Replace all images with a new img tag that has
	 * a max width.
	 * 3/1/2013
	 */
	//$p[0]['description'] = str_ireplace('<img ', '<img style="max-width: 600px;"', $p[0]['description']);
	/*
	 * Add ID to image
	 * 11/9/2012
	 */
	if ($_SESSION['userbrowser'] == 'mobile')
	{
		$p[0]['description'] = str_ireplace('<img ', "<img style='max-width: 335px; max-height: 400px;' title='{$p[0]['title']}' alt='{$p[0]['title']}' ", $p[0]['description']);
	}
	else
	{
		$p[0]['description'] = str_ireplace('<img ', "<img style='max-width: 600px; max-height: 600px;' title='{$p[0]['title']}' alt='{$p[0]['title']}' ", $p[0]['description']);
	}


	/*
	 * The editable time is 4 hours
	 * 4/15/2012
	 */
	$editTime = $p[0]['date_asked'] + 14400;
	if ($editTime > time()) {
		$p[0]['canedit'] = 1;
	} else {
		$p[0]['canedit'] = 0;
	}

   /*
	* Does this post have a short_url?
	* If not, grab it.
	* 5/25/2013
	*/
	if (empty($p[0]['short_url']))
	{
	  $p[0]['short_url'] = GetAndSetShortUrl($p[0]['PID'], 'faq');
	}

	/*
	 * Fetch the Users Level
	 */
	// $p[0]['userlevel'] = GetUserLevelFromId($uid);


	/*
	 * This will determine the rating a question
	 * has based on up/down votes
	 *
	 */
	$ratingTitle = preg_replace("/[^A-Za-z0-9\& +,-]/", ' ', $p[0]['title']);
	$ratingTitle = trim($ratingTitle);
	$ratingTitle = "'" . $ratingTitle . "'";
	$p[0]['totalRatings'] = $p[0]['upvotes'] + $p[0]['downvotes'];
	$starRating = ((legacyDivide($p[0]['upvotes'], ($p[0]['upvotes'] + $p[0]['downvotes']))) * 100) / 20; // no votes: NAN as on 7.4
	$starRating = round($starRating);

	/*
	 * Build the html
	 */
	if ($p[0]['totalRatings'] <= 0)
	{
		$content = "";
	}
	else
	{
		$content = "<div class='smalllighter' itemprop='aggregateRating' itemscope itemtype='http://schema.org/AggregateRating'>
					   <span itemprop='itemReviewed'>{$ratingTitle}</span>
					   <span>is ranked
					   <span itemprop='ratingValue'>{$starRating}</span> out of <span itemprop='bestRating'>5</span></span>.
					   Based on <span itemprop='ratingCount'>{$p[0]['totalRatings']}</span> user reviews.
					</div>";
	}

	/*
	 * Assign the value to the post
	 */
	$p[0]['footerRatingContent'] = $content;

	/*
	 * Fetch the google+ profile
	 * of the user who created the FAQ
	 * 7/9/2013
	 */
	 $googleplus_profile = GetGooglePlusProfileFromId($uid);

	 /*
	 * Google+ Author
	 * 7/9/2013
	 */
	if (!empty($googleplus_profile))
	{
	}

	/*
	 * If this is a scheduled post, let's get the date and
	 * show that to the user.
	 * 4/27/2017
	 */
	if ($p[0]['status'] == 2)
	{
		STemplate::assign('useralert', $lang['2603'] . GetDateBasedOnTimezone($p[0]['date_scheduled']));
	}

	/*
	 * Do some extra work for the UNI theme.
	 * 06/27/2018
	 */
	if ($config['themeUni']	== 1 && legacyNumber($_REQUEST['amp']) == 0) // the URL's text compared as 7.4 did: 8 compares 'abc' with a number as text (#1925)
	{
		if ($p[0]['userlevel'] > 5)
		{
			$newUserLevel 			= $p[0]['userlevel'] - 3;
			$p[0]['userlevel'] 		= 'X' . "<sup>{$newUserLevel}</sup>";
		}
	}
	else
	{
		/*
		* make the level 1 if 0
		* 3/31/2012
		*/
		if ($p[0]['userlevel'] == 0) {
			$p[0]['userlevel'] == 1;
		} else if ($p[0]['userlevel'] == 4) {
			$p[0]['userlevel'] == 'bigx';
		}
	}

	/*
	 * Fetch how the browsing user
	 * has voted.
	 * 4/12/2012
	 */
	$p[0]['uservote']	= GetUserVote($p[0]['PID'], 'ratings_faq', $_SESSION['USERID']);
	$p[0]['voters']		= GetVoters($p[0]['PID'], 'ratings_faq');
	$p[0]['badges'] 	= json_decode($p[0]['badges']);

	/*
	 * The SEO URL
	 */
	$seoUrl = $config['baseurl'] . '/faq/' . $PD . '/' . $p[0]['seo'];

	/*
	 * Regardless of what type, if there is
	 * meta details set those.
	 * Added 11/9/2011
	 */
	if (!empty($p[0]['metatitle']))
	{
		$pagetitle = $p[0]['metatitle'];
	}
	else
	{
		STemplate::assign('pagetitle',strip_tags($p[0]['question']));
	}

	if (!empty($p[0]['metakeywords']))
	{
		$config['metakeywords'] = $p[0]['metakeywords'];
	}
	else
	{
		$config['metakeywords'] = strip_tags($p[0]['tags']);
		STemplate::assign('metakeywords', strip_tags($p[0]['tags']));
	}

	if (!empty($p[0]['metadescription']))
	{
		$config['metadescription'] = $p[0]['metadescription'];
	}
	else
	{
		$config['metadescription'] = formatMetaDescription($p[0]['description']);
	}

	if(is_numeric($PD) && $PD > 0)
	{
		$tags = explode(" ", $p[0]['tags']);

		/*
		 * Get the user last submit time
		 * 10/3/2012
		 */
		if ($_SESSION['USERID'] > 0) {
			$lastSubmitTime = GetLastSubmissionTime($_SESSION['USERID']);
		}

		/*
		 * User is subscribing
		 * 6/21/2016
		 */
		if ($_REQUEST['subscribe'] == 1 && $_SESSION['USERID'] > 0 && $_REQUEST['token'] == $_SESSION['token'])
		{
			$query 		= "SELECT count(subid) as total FROM questions_subscribe
	    					WHERE USERID='".escape($_SESSION['USERID'])."'
	    						AND quesid='".escape($PD)."'
	    						";
		    $executequery	= $conn->execute($query);

		    if ($executequery->fields['total'] <= 0)
		    {
			    $query = "INSERT INTO questions_subscribe (USERID, quesid, status, date)
			    			VALUES ('".escape($_SESSION['USERID'])."',
			    				'".escape($PD)."',
			    				1,
			    				UNIX_TIMESTAMP(NOW())
			    			)";
			    $conn->execute($query);
		    }
		    else
		    {
			    $query = "UPDATE questions_subscribe SET status=1
						WHERE quesid='".escape($PD)."'
							AND USERID='".escape($_SESSION['USERID'])."'
					 ";
				$conn->execute($query);
		    }
		}

		/*
		 * User is unsubscribing
		 * 6/21/2016
		 */
		if ($_REQUEST['unsubscribe'] == 1 && $_SESSION['USERID'] > 0 && $_REQUEST['token'] == $_SESSION['token'])
		{
			$query = "UPDATE questions_subscribe SET status=2
						WHERE quesid='".escape($PD)."'
							AND USERID='".escape($_SESSION['USERID'])."'
					 ";
			$conn->execute($query);
		}

		/*
		 * User is submitting a message!
		 * Added 10/21/2011
		 */
		if ($_REQUEST['submg'] == 1)
		{
			/**
			 * Must be verified before submitting a comment
			 * 2022-06-21 09:21:31 - SE
			 */
			if (!empty($_SESSION['USERID']) && is_numeric($_SESSION['USERID']) && $__loggedUserDetails['phone_verified'] == 1 && $__loggedUserDetails['verified'] == 1)
			{
				/*
				 * Determine if the user can create new content
				 * 7/17/2015
				 */
				if ($_SESSION['USERID'] >= 0)
				{
					if (IsContentRestricted(escape($_SESSION['USERID'])) == 1 || $siftscore >= $config['faqContent'])
					{
						$error = $lang['2050'];

						//TEMPLATES BEGIN
						//TEMPLATES END
						die();
					}
				}

				if (!empty($_REQUEST['message_body']))
				{
					if (!DetectSpamLinkContent($_SESSION['USERID'], $_REQUEST['message_body']))
					{ // Removed !SearchForSpam($_REQUEST['message_body']) &&
						if (CountWords($_REQUEST['message_body']) >= 5)
						{
							/*
							 * Is the user repeating too many phrases?
							 * 8/22/2013
							 */
							if (1 == 1) //!SearchForRepeatedPhrases($_REQUEST['message_body']))
							{
								if (!$lastSubmitTime)
								{
									if (!IsAnswerMadeAlready($_REQUEST['message_body']))
									{
										/*
										 * Has this answer already been made somewhere?
										 * 7/27/2013
										 */


										/*
										 * Ok, lets enter this damn message!
										 */
										$USERID   	  = escape($_SESSION['USERID']);
										$parentid	  = escape($_REQUEST['parentid']);
										$message_body = escape(cleanit_keeptags(ConditionTextBeforeSubmit($_REQUEST['message_body'])));
										$query   	  = "INSERT INTO answers (quesid, userid, parentid, answer, date_answered, status, ip_address)
											VALUES ({$PD}, {$USERID}, {$parentid}, '{$message_body}', UNIX_TIMESTAMP(NOW()), '1', '{$_SERVER['REMOTE_ADDR']}')";

										$conn->execute($query);

										/*
										 * Clear out the message
										 */
										$_REQUEST['message_body'] = "";

										/*
										 * Update User Answer Count
										 */
										update_FaqAnswerCount($USERID);

										/*
										 * Update Question Answer Count
										 */
										update_FaqAnswerQuestionCount($PD);

										/*
										 * Determine if the user should get an email
										 * 6/21/2016
										 */
										$query 			= "SELECT faq_autoscribe
															FROM seoclerks.members
															WHERE USERID='".escape($_SESSION['USERID'])."'";
										$executequery	= $conn->execute($query);
										$faqAutoScribe 	= $executequery->fields['faq_autoscribe'];


										/*
										 * If the user is FAQ Autoscribe,
										 * insert them into the subscribe DB
										 * 6/21/2016
										 */
										if ($faqAutoScribe == 1)
										{
											$query 		= "SELECT count(subid) as total
															FROM questions_subscribe
															WHERE USERID='".escape($_SESSION['USERID'])."'
															AND quesid='".escape($PD)."'
															";
											$executequery	= $conn->execute($query);

											if ($executequery->fields['total'] <= 0)
											{
												$query = "INSERT INTO questions_subscribe (USERID, quesid, status, date)
															VALUES ('".escape($_SESSION['USERID'])."',
																'".escape($PD)."',
																1,
																UNIX_TIMESTAMP(NOW())
															)";
												$conn->execute($query);
											}
										}

										/*
										 * Send the message
										 */
										$subject = $lang['603'] . ' - ';
										$message = $lang['468'] .  $lang['604'];

										/*
										 * Some email clients the URL is not a link
										 * 7/15/2017
										 */
										$seoHref = "<a href='{$seoUrl}?utm_source=faq&utm_medium=email&utm_campaign={$pd}'>{$seoUrl}</a>";

										/*
										 * Replace the contents
										 */
										$message = str_ireplace('<gtitle>', stripslashes($title), $message);
										$message = str_ireplace('<itemurl>', $seoHref, $message);

										/*
										 * Send out the update!
										 */
										 if ($USERID != $uid)
										 {
											$query 			= "SELECT receive_faq_email
																FROM seoclerks.members
																WHERE USERID='".escape($uid)."'";
											$executequery	= $conn->execute($query);

											if ($executequery->fields['receive_faq_email'])
											{
												sendUpdateEmail($uid, $subject, $message);
											}

											/*
											 * Add an alert that a new comment was
											 * made to the service owner.
											 * 5/1/2013
											 */
											InsertUserAlert($uid, 'faq', $PD, 'response', $USERID);
										}

										/*
										 * If someone is responding to someone else,
										 * send them an update email as well.
										 * 6/21/2016
										 */
										if ($parentid > 0 && $USERID != $uid)
										{
											$query 			= "SELECT userid
																FROM answers
																WHERE ansid='".escape($parentid)."'
																AND USERID!='".escape($uid)."'
																";
											$executequery	= $conn->execute($query);
											$reply_USERID 	= $executequery->fields['userid'];

											/*
											 * Send the message
											 */
											$subject = $lang[2352] . ' - ';
											$message = $lang[468] .  $lang[2353];

											/*
											 * Some email clients the URL is not a link
											 * 7/15/2017
											 */
											$seoHref = "<a href='{$seoUrl}?utm_source=faq&utm_medium=email&utm_campaign={$pd}'>{$seoUrl}</a>";

											/*
											 * Replace the contents
											 */
											$message = str_ireplace('<gtitle>', stripslashes($title), $message);
											$message = str_ireplace('<itemurl>', $seoHref, $message);

											/*
											 * Make sure the user wants an email
											 * 6/21/2016
											 */
											$query 			= "SELECT receive_faq_email
																FROM seoclerks.members
																WHERE USERID='".escape($reply_USERID)."'
																";
											$executequery	= $conn->execute($query);

											if ($executequery->fields['receive_faq_email'] && $reply_USERID != $_SESSION['USERID'])
											{
												sendUpdateEmail($reply_USERID, $subject, $message);
											}

											/*
											 * Add an alert that a new comment was
											 * made to the service owner.
											 * 5/1/2013
											 */
											InsertUserAlert($reply_USERID, 'faq', $PD, 'comresponse', $USERID);
										}

										/*
										 * Email everyone that is subscribed
										 * to the discussion
										 * 6/21/2016
										 */
										$query = "SELECT q.USERID
													FROM questions_subscribe as q,
														seoclerks.members as m
													WHERE m.USERID=q.USERID
														AND q.status=1
														AND m.receive_faq_email=1
														AND q.USERID!='".escape($uid)."'
														AND q.USERID!='".escape($_SESSION['USERID'])."'
														AND q.quesid='".escape($PD)."'
													";

										if ($parentid > 0)
										{
											$query .= " AND q.USERID!='".escape($reply_USERID)."' ";
										}

										$results 	= $conn->execute($query);
										$subUsers 	= $results->getrows();

										foreach ($subUsers as $subUser)
										{
											/*
											 * Send the message
											 */
											$subject = $lang[2364] . ' - ';
											$message = $lang[468] .  $lang[2365];

											/*
											 * Some email clients the URL is not a link
											 * 7/15/2017
											 */
											$seoHref = "<a href='{$seoUrl}?utm_source=faq&utm_medium=email&utm_campaign={$pd}'>{$seoUrl}</a>";

											/*
											 * Replace the contents
											 */
											$message = str_ireplace('<gtitle>', stripslashes($title), $message);
											$message = str_ireplace('<itemurl>', $seoHref, $message);

											sendUpdateEmail($subUser['USERID'], $subject, $message);
										}

										/*
										 * Blank out message
										 */
										$message = "";
									}
									else
									{
										/*
										 * Answer is already made
										 */
										$error = $lang['1527'];
									}
								}
								else
								{
									/*
									 * Submissions are being made to fast
									 * 10/3/2012
									 */
									$error = $lang['1027'] . $lastSubmitTime . ' ' . $lang['443'];
								}
							}
							else
							{
								/*
								 * Too many repeated phrases
								 * 8/22/2013
								 */
								$error .= $lang[1665];
							}
						}
						else
						{
							/*
							 * Word count is less than 10 words
							 * 10/3/2012
							 */
							 $error = $lang['1025'];
						}
					}
					else
					{
						/*
						 * Determine if the message is spam or not
						 * 3/22/2012
						 */
						$error = $lang['748'];
					}
				}
				else
				{
					/*
					 * Blank Comment
					 */
					$error = $lang['605'];
				}
			}
		}


		/*
		 * Lets get User answers now
		 * Comments added on 11/29/2011
		 */
		$query = "SELECT a.answer, a.USERID, a.upvotes, a.downvotes, a.ansid, a.parentid, a.combined_votes, a.date_answered,
					b.username, b.userlevel, b.profilepicture FROM answers a, seoclerks.members b
					WHERE a.quesid='".escape($PD)."' AND a.userid=b.USERID and b.status='1' AND a.status=1
					ORDER BY a.combined_votes DESC, a.date_answered asc";
		$results=$conn->execute($query);
		$answers = $results->getrows();

		/*
		 * Sort the array properly
		 * 4/12/2012
		 */
		$answers = SortArrayByCriteria(0, 0, $answers, 'ansid', 'parentid');

		foreach ($answers as &$ans)
		{
			/*
			 * Replace images here with a link to the actual
			 * image and then reduce the size here.
			 * 11/9/2012
			 */
			$images = getImagesFromContent($ans['answer']);
			foreach ($images[0] as $key => $image)
			{
				$ans['answer'] = str_ireplace($image, '[url=' . $images[1][$key] . ']' . $image . '[/url]', $ans['answer']);
			}

			// $ans['answer']	  = ReplaceAttachments($ans['ansid'], 'answer', $ans['answer']); // No longer used/needed

			/**
			 * Adjust colors based on mode
			 *
			 * 2026-03-24 06:46:45 JD
			 */
			$ans['answer']		= formatColorBasedOnMode($ans['answer']);

			$ans['answer']	  	= textConvertAffiliateSites($ans['answer']);
			$ans['uservote']   	= GetUserVote($ans['ansid'], 'ratings_faqanswers', $_SESSION['USERID']);
			$ans['answerorig']	= ConditionOrig($ans['answer']);
			$ans['answer'] 	  	= ConditionText($ans['answer']);
			//$ans['answer'] 	  = ucwords(strtolower($ans['answer']));
			$ans['voters']	  	= GetVoters($ans['ansid'], 'ratings_faqanswers');
			$ans['depth'] 	  	= $ans['depth'] * 40;

			/**
			 * Format the text to the orignal with bbcode
			 *
			 */
			$ans['commentorig'] 		= str_ireplace('[[', '[', $ans['answerorig']);
			$ans['commentorig'] 		= CorrectUnorderedBBCodeList($ans['commentorig']);

			/*
			 * Load a time ago type date for the new theme
			 * 8/26/2018
			 */
			if($config['themeUni']	== 1)
			{
				$ans['display_date'] = GetTimeAgo($ans['date_answered']); //date("F j, Y, g:i a", $ans['date_answered']);
			}
			else
			{
				$ans['display_date'] = date("F j, Y, g:i a", $ans['date_answered']);
			}

			/*
			 * Replace all images with a new img tag that has
			 * a max width.
			 * 3/1/2013
			 */
			//$ans['answer'] = str_ireplace('<img ', '<img style="max-width: 600px;"', $ans['answer']);
			/*
			 * Add ID to image
			 * 11/9/2012
			 */
			$ans['answer']  = str_ireplace('<img ', "<img style='max-width: 600px; max-height: 600px;' title='{$p[0]['title']}' alt='{$p[0]['title']}' ", $ans['answer']);

			/*
			 * The editable time is 4 hours
			 * 4/13/2012
			 */
			$editTime = $ans['date_answered'] + 14400;
			if ($editTime > time())
			{
				$ans['canedit'] = 1;
			}
			else
			{
				$ans['canedit'] = 0;
			}

			/*
			 * This is for the amp pages to
			 * enabled the required JS
			 * 5/9/2017
			 */
			if (stristr($ans['answer'], 'youtube'))
			{
				$ampyoutube = 1;
			}
			if (stristr($ans['answer'], 'vimeo'))
			{
				$ampvimeo = 1;
			}

		}


		/*
		 * Update the view count
		 */
		update_Faqviewcount($pid);
	}

	/*
	 * Get related questions for users to
	 * view in the right-hand sidebar
	 * 7/27/2013
	 */
	/*$searchtags = explode(" ", $gtags); // Was gtags, moved to title without stop words
	for($i=0;$i<count($searchtags);$i++)
	{
		$addme .= " OR tags like '%".escape($searchtags[$i])."%'";
	}*/
	$searchtags = explode(" ", removeStopWords($title)); // Was gtags, moved to title without stop words
	for($i=0;$i<count($searchtags);$i++)
	{
		if (strlen($searchtags[$i]) >= 4)
		{
			$addme .= " OR question like '%".escape($searchtags[$i])."%'";
		}
	}
	$query	=	"SELECT quesid, question, seo, userid
					FROM questions
					WHERE quesid!='".escape($pid)."' AND status='1'
						AND (question like '%".escape(removeStopWords($title))."%' $addme)
					-- ORDER BY RAND()
					LIMIT 15"; //AND (question like '%".escape($gtags)."%' $addme)

	/*
	 * removed order by rand() on 5/29/2013 to
	 * increase speed from .5-2seconds to .0078
	 */
	$results			= $conn->CacheExecute(240, $query);
	$relatedQuestions 	= $results->getrows();

	/**
	 * Randomize our rows using PHP array function for speed increase
	 */
	$relatedQuestions 	= randomizeArray($relatedQuestions, 5);

	foreach ($relatedQuestions as &$relatedQ)
	{
		$relatedQ['profilepicture'] = insert_get_member_profilepicture(array('USERID' => $relatedQ['userid']));
	}

	/*
	 * Expire the sticky if it is after the date
	 * 6/14/2016
	 */
	if ($p[0]['sticky'] && time() > $p[0]['sticky_expire'])
	{
		$query = "UPDATE questions SET sticky=0 WHERE quesid='".escape($PD)."'";
		$conn->execute($query);
	}

	/*
	 * See if the user is subscribed or not
	 * 6/21/2016
	 */
	if ($_SESSION['USERID'] > 0)
	{
		$query = "SELECT COUNT(subid) AS total
					FROM questions_subscribe
					WHERE USERID='".escape($_SESSION['USERID'])."'
						AND quesid='".escape($PD)."'
						AND status=1
					";
		$executequery	= $conn->execute($query);
		if ($executequery->fields['total'] > 0)
		{
			$subscribed = 1;
		}
		else
		{
			$subscribed = 0;
		}
	}

	/*
	 * Update the viewed content so workers
	 * only see it once. :)
	 * 11/9/2011
	 */
	if ($_SESSION['USERID'] == $p[0]['USERID']) {
		$query = "UPDATE questions SET author_bookmarktip=1 WHERE quesid='".escape($PD)."'";
		$conn->execute($query);
	}

	/*
	 * This isn't required for the uni-theme since it is
	 * in a droplet and loads via AJAX.
	 * 11/7/2018
	*/
	if ($config['themeUni'] != 1)
	{
		/*
		* Fetch a randomly features service to advertise
		* on the right hand side of the FAQ section
		* 6/27/2016
		*/
		$query = "SELECT p.*, m.USERID, m.profilepicture, m.username, m.userlevel,
						m.lastlogin, m.ip, m.lip
					FROM posts as p,
						seoclerks.members as m
					WHERE m.USERID=p.USERID
						AND p.alwaysfeatured_upgrade>0
						AND p.feat=1
						AND p.active=1
						AND p.type!=99
					ORDER BY RAND()
					LIMIT 3
				";

		$randomAdQuery			= $conn->CacheExecute(60, $query);
		$randomAd	 			= $randomAdQuery->getrows();
		$randomAd				= ChangePostData($randomAd);
	}

	/*
	 * Get all of the users who are currently in the
	 * FAQ section
	 * 6/25/2016
	 */
	$query = "SELECT USERID, username FROM members_ledger
				WHERE script='".escape($config['viewFaqScript'])."'
					AND querystring LIKE '%id=".escape($PD)."%'
					AND added>=UNIX_TIMESTAMP(NOW())-1200
				GROUP BY USERID
	";
	$executeUsersOnline 	= $conn->CacheExecute(15, $query);
	$viewUsers 				= $executeUsersOnline->getrows();

	foreach ($viewUsers as &$user)
	{
		$query     			= "SELECT USERGROUP FROM seoclerks.members WHERE USERID='{$user['USERID']}'";
		$result    			= $conn->CacheExecute(240, $query);
		$user['USERGROUP']  = $result->fields['USERGROUP'];

		if ($user['USERGROUP'] == 'admin')
		{
			$user['class']		= 'justred';
		}
		else if ($user['USERGROUP'] == 'mod' || $user['USERGROUP'] == 'faqmod' || $user['USERGROUP'] == 'unpaidfaq')
		{
			$user['class'] 		= 'justblue';
		}
		else
		{
			$user['class'] 		= '';
		}
	}

}
else
{
	header("HTTP/1.1 301 Moved Permanently");
	header("location: $config[baseurl]/faq");
}

/*
 * If this is an AJAX call, just return the
 * the viewfaqbit
 * 7/29/2013
 */
if ($_REQUEST['ajax'] == 1)
{
	/*
	 * If there is an error, let's show that as a
	 * gritter alert so that the user realizes they
	 * did not submit it.
	 * 5/4/2017
	 */
	if (!empty($error))
	{
		if ($config['themeUni']	== 1 && $_REQUEST['amp'] != 1)
		{
			$hasDanger[0]['id'] 		= 'comment-text';
			$hasDanger[0]['message']	= $error;
			$hasDanger[0]['errorid']	= 'comment-text-error';
			echo json_encode($hasDanger);
			die();
		}

		/*
		 * Add an alert for the current user
		 * 4/25/2017
		 */
		InsertGritterAlert($lang['2613'], $error, false, 9000, 'error');
		$gritterJs = GetGritterSession(false);
		if (!empty($gritterJs))
		{
		}
	}
	else
	{
		/*
		 * Add an alert for the current user
		 * 4/25/2017
		 */
		InsertGritterAlert($lang['2614'], $lang['2615'], false, 5000, 'success');
		$gritterJs = GetGritterSession(false);
		if (!empty($gritterJs))
		{
		}
	}

	if ($config['themeUni']	== 1 && $_REQUEST['amp'] != 1)
	{
		$redirectPath	= '/faq/' . $p[0]['quesid'] . '/' . $p[0]['seo'];

		include 'views/components/view_comment-bit.php';
		die();
	}
	else
	{
	}
}
else
{
	//TEMPLATES BEGIN
	$theme = "viewfaq.tpl";

	/*
	 * AMP support removed - 2026-09-22. /amp URLs now 301 to the
	 * canonical page; this always renders the normal page.
	 */
	if ($config['themeUni']	== 1)
	{
		/*
		* Affiliate URL for promotion
		* 10/28/2012
		*/
		if ($__loggedUserDetails['USERID'] > 0)
		{
			$affUrl = $config['aurl'] . '/linkin/' . $__loggedUserDetails['USERID'] . '/faq/' . $p[0]['quesid'] . '/' . seo_clean_titles($p[0]['title']);
		}
		else
		{
			$affUrl = $config['baseurl'] . '/faq/' . $p[0]['quesid'] . '/' . seo_clean_titles($p[0]['title']);
		}

		$shareComponent['title'] 	= $lang[3550];
		$shareComponent['link'] 	= $affUrl;

		$config['include']['modals'][0] = 'views/modal/view_modal-share.php';

		/**
		 * Scheme content for google
		 */
		$schematype 		= 'Article';
		$schemaheadline 	= cleanit($p[0]['title']);

		/**
		 * A discussion with a header image is represented by that image,
		 * the way a blog post is by its main image - it is also what gets
		 * shared, because view_header.php feeds og:image from here.
		 * Falling back to the author's picture otherwise, as before.
		 *
		 * No size is published for the header image: the only way to know
		 * it is to measure the file, and it is not necessarily on this
		 * machine any more (issue #979). view_header.php leaves the two
		 * keys out rather than printing empty ones.
		 *
		 * 2026-09-20
		 */
		if (!empty($p[0]['image_url']))
		{
			$schemaimage 	= $p[0]['image_url'];
			$schemaimageH 	= '';
			$schemaimageW 	= '';
		}
		else
		{
			/*
			 * The author's picture comes from $userDetails, as it does in
			 * views/faq/view_view-faq.php. This used $p[0]['profilepicture'],
			 * which the discussion query never selects, so og:image was
			 * the membersprofilepic folder itself on every such page.
			 * getProfileImageFromImage() supplies the site default for an
			 * author who has no picture.
			 *
			 * 2026-09-22
			 */
			$schemaimage 	= $config['membersprofilepicurl'] . '/' . getProfileImageFromImage($userDetails['profilepicture']);
			$schemaimageH 	= 100;
			$schemaimageW 	= 100;
		}
		$schemapublishdate	= $p[0]['date_asked'];
		$schemaupdated		= $p[0]['updated'];
		$schemaauthor		= $p[0]['username'];
		$schemapublishertype = 'Organization';

		$config['pagetitle']	= $title;

		/*
		 * Set some variables used in the comment bit to route
		 * the posts correctly.
		 * 8/13/2018
		 */
		$isService 	= 0;
		$isFaq		= 1;
		$spamtype   = 'answer'; // Used in the comment bit for reporting spam

		include 'views/header/view_header-loader.php';
		include 'views/faq/view_view-faq.php';
		include 'views/footer/view_footer-loader.php';
	}
	else
	{
	}
	//TEMPLATES END
}
?>
